import TurnTableSystem from "../system/TurnTableSystem";
import Util from "../../../StartAb/Util";

const { ccclass, property, requireComponent } = cc._decorator;

@ccclass
@requireComponent(cc.Label)
export default class TurnTableTimer extends cc.Component {

    _label: cc.Label = null;

    onLoad() {
        this._label = this.node.getComponent(cc.Label);
    }

    start() {
        this.updatePerSecond();
        this.schedule(this.updatePerSecond, 1.0);
    }

    updatePerSecond() {
        this.updateTimerText();
    }

    updateTimerText() {
        if(TurnTableSystem.isNoBlood() == false) {
            this._label.string = "";
            return Date.now()
        }
        let now = new Date();
        let today000 = new Date();
        today000.setHours(0);
        today000.setMinutes(0);
        today000.setSeconds(0);
        let secDiff = (86400 - (now.getTime()/1000 - today000.getTime()/ 1000))
        let str = Util.secondToStr(secDiff, true)
        this._label.string = str;
    }
}
